package com.atguigu.distributed.lock.juc;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class MyThreadPoolDemo {
    public static void main(String[] args) {
        System.out.println(Runtime.getRuntime().availableProcessors());
        //ExecutorService threadPool = Executors.newFixedThreadPool(5);//一池5个处理线程
        ExecutorService threadPool = Executors.newSingleThreadExecutor();//一池1个处理线程
        //ExecutorService threadPool = Executors.newCachedThreadPool();//一池N个处理线程

        try {
            for (int i = 1; i <=20 ; i++) {
                threadPool.execute(()->{
                    System.out.println(Thread.currentThread().getName()+"\t 办理业务");
                });
                try{
                    TimeUnit.MILLISECONDS.sleep(200);
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
                }catch (Exception e){
                    e.printStackTrace();
                }finally {
                    threadPool.shutdown();
                }
    }
}
